{% load debate_tags static i18n %}

<nav class="navbar navbar-expand-lg navbar-light">

  {# Decisions about whether to show items in the menu are based on the role of the user (not the view). #}
  {% blocktrans trimmed asvar logo_alt %}
    Tabbycat Logo
  {% endblocktrans %}
  {% if all_tournaments.count > 1 or user.is_authenticated %}
    <div class="nav-item dropdown">

      <button class="btn btn-link mr-2 p-0 navbar-brand dropdown-toggle" id="tournamentdrop"
              data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        {% if on_local %}
          {% include "nav/logo_local.html" with width=33 height=33 alt=logo_alt %}
        {% else %}
          {% include "nav/logo.html" with width=33 height=33 alt=logo_alt %}
        {% endif %}
        {% if tournament %}{{ tournament }}{% else %}Tabbycat{% endif %}
      </button>

      <div class="dropdown-menu" aria-labelledby="tournamentdrop">

        {% for tournament in all_tournaments %}

          {% if user.is_superuser %}
            <a class="dropdown-item px-2" href="{% url 'tournament-admin-home' tournament_slug=tournament.slug %}">
              <i data-feather="settings"></i>
              {% blocktrans trimmed %}
                Administrator area for <strong>{{ tournament }}</strong>
              {% endblocktrans %}
            </a>
          {% endif %}

          {% if user.is_authenticated %}
            <a class="dropdown-item px-2" href="{% url 'tournament-assistant-home' tournament_slug=tournament.slug %}">
              <i data-feather="pocket"></i>
              {% blocktrans trimmed %}
                Assistant area for <strong>{{ tournament }}</strong>
              {% endblocktrans %}
            </a>
          {% endif %}

          <a class="dropdown-item px-2" href="{% url 'tournament-public-index' tournament_slug=tournament.slug %}">
            {% if user.is_authenticated %}
              <i data-feather="globe"></i>
              {% blocktrans trimmed %}
                Public area for <strong>{{ tournament }}</strong>
              {% endblocktrans %}
            {% else %}
              <i data-feather="award"></i>
              {{ tournament }}
            {% endif %}
          </a>

          <div class="dropdown-divider"></div>
        {% endfor %}

        <a class="dropdown-item px-2" href="/"><i data-feather="home"></i>{% trans "Site Home" %}</a>
      </div>

    </div>
  {% else %}
    <div class="nav-item">

      {% if tournament %}
        <a class="navbar-brand" href="{{ tournament.get_public_url  }}">
          {% include "nav/logo.html" with width=33 height=33  alt=logo_alt %}
          {{ tournament }}
        </a>
      {% else %}
        <a class="navbar-brand" href="/">
          {% include "nav/logo.html" with width=33 height=33 alt=logo_alt %}
          Tabbycat
        </a>
      {% endif %}

    </div>
  {% endif %}

  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsed-main-nav" aria-controls="collapsed-main-nav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse pt-3 pt-md-0 pb-2 pb-md-0" id="collapsed-main-nav">

    <ul class="navbar-nav mr-auto">

      {% if user_role == "assistant" %}
        {% include "nav/assistant_nav.html" %}
      {% else %}
        {% include "nav/public_nav.html" %}
      {% endif %}

    </ul>

    <ul class="navbar-nav navbar-my-lg-0">
      <li class="nav-item">
        {% if user.is_authenticated %}
          <a class="nav-link" href="{% url 'logout' %}">
            {% trans "Log Out" %} ({{ user }})
          </a>
        {% else %}
          <a class="nav-link" href="{% url 'login' %}">
            {% trans "Login" %}
          </a>
        {% endif %}
      </li>
    </ul>

  </div>

</nav>
